// 最长回文子串

let longestPalindrome = function (s) {
  if (s < 2) return s;
  let res = "";
  const len = s.length;
  for (let i = 0; i < len; i++) {
    if (res.length === len) break;
    walk(i, i);
    if (s[i] === s[i + 1]) {
      walk(i, i + 1);
    }
  }
  function walk(l, r) {
    while (l >= 0 && r < len && s[l] === s[r]) {
      l--;
      r++;
    }
    if (r - l - 1 > res.length) {
      res = s.slice(l + 1, r);
    }
  }
  return res;
};